<?php
// +----------------------------------------------------------------------
// | KungfuCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.0ya0.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 三藏 <dungang@126.com> <http://www.0ya0.com>
// +----------------------------------------------------------------------

defined('BASEPATH') OR exit('No direct script access allowed');

class Action_Before_Hooks {

    public function action_before(){
        $CI =& get_instance();
        $CI->load->helper(array('url'));
        if (!empty($_SESSION['error']) && $CI->router->method !== $_SESSION['error']) {
            if ($_SESSION['error'] === 'environment'){
                redirect('setup/environment');
            }
        }
        $CI->load->helper('language');
        if (empty($_SESSION['lang'])) {
            $languages = $CI->agent->languages();
            $_SESSION['lang'] = 'english';
            if(is_array($languages)){
                foreach($languages as $lang) {
                    if (preg_match('/zh/',$lang)){
                        $_SESSION['lang'] = 'chinese';
                        break;
                    }
                }
            }
        }
        $CI->lang->load('install',$_SESSION['lang']);
    }

}